import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import ThemedImage from '@theme/ThemedImage';

# Declarative Capsule Spec

The foundation of Rig is our Capsule specification. The Capsule exists as a two-stage object consisting of
- Platform Capsule
- Kubernetes Capsule

You can see a full example of both [here](/operator-manual/capsule-spec).

The Platform Capsule is the spec which the end-user of Rig will be working with. This spec (among other things) abstracts away cluster-level information in favor of Project and Environment terminology. The Rig Platform will translate a Platform Capsule into a Kubernetes Capsule, which is our [CustomResourceDefinition](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) (CRD) defining the Capsule functionality within a Kubernetes cluster. The Rig Operator will from a Kubernetes Capsule spawn derived Kubernetes resources which will be owned by the corresponding Kubernetes Capsule. It will also watch these derived resources and undo any changes applied to them which conflicts with their Capsule parent. Updating these resources can only be done by updating the corresponding Kubernetes Capsule. The resources we (can) spawn are

- [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
- [Service](https://kubernetes.io/docs/concepts/services-networking/service/)
- [TLS Certificate](https://cert-manager.io/docs/reference/api-docs/#cert-manager.io/v1.Certificate)
- [Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/)
- [Horizontal Pod Autoscaler](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/)
- [Cron Job](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/)

ConfigMaps and Secrets used by a capsule is not owned by the capsule though. These will be created by the Platform and can be updated independently of the capsules. The operator, however, will watch those config files and redeploy instances if configs or secrets they depend on have been changed.


<img src="/img/operator-manual/capsule-spec-translation.png" alt="Platform Capsule"/>
